import {
	BaseUrl
} from "./config.js"

export function getUserByOpenId(openId) {
	return uni.request({
		method: "GET",
		url: BaseUrl + "/users/getByOpenID",
		data: {
			openId
		}
	}).then(res => res.data)
}

export function getUserByPhoneOpenId({
	openId,
	phone
}) {
	return uni.request({
		method: "GET",
		url: BaseUrl + "/users/createByOpenId",
		data: {
			openId,
			phone
		}
	}).then(res => res.data)
}

export function getUserByPassword({
	phone,
	password
}) {
	return uni.request({
		method: "GET",
		url: BaseUrl + "/users/getByPassword",
		data: {
			password,
			phone
		}
	}).then(res => {
		// console.log("res", res);
		if (!res.data.data) return null
		res.data.data.role = parseInt(res.data.data?.role)
		// console.log("user", res.data.data);
		return res.data.data
	})
}

export function changePassword({
	phone,
	oldPassword,
	newPassword
}) {
	return uni.request({
		method: "POST",
		url: BaseUrl + "/users/alterPassword",
		data: {
			phone,
			oldPassword,
			newPassword
		}
	}).then(res => {
		return res.data
	})
}